<!--用户管理-->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="li => selection = li">
    </ex_super_table_page>

    <ex_super_dialog_form ref="rechargeDialog" v-bind="rechargeDialog" @afterSubmitSuccess="reload()">
    </ex_super_dialog_form>

    <ex_super_dialog_form ref="aduitDialog" v-bind="aduitDialog" @afterSubmitSuccess="reload()">
    </ex_super_dialog_form>
    <ex_super_dialog_form ref="detailDialog" v-bind="detailDialog" />

  </div>
</template>
<script>

import business_function from "@/common/business_function";

import FmsCurrencyChoose from '@/component/fms/fms-currency-choose.vue'


import superTablePageFunction from '@/mixin/super-table-page-function';


export default {

  title: "label_fms_recharge_record_manage",
  components: { FmsCurrencyChoose, },
  mixins: [superTablePageFunction],
  data() {


    return {
      selection:[],
      option: {
        search: {
          model: [
            {
              label: "label_fms_account_cmp_customer",
              key: "customerIds",
              type: 'common_customer_choose',
              attrs: { multiple: true },
              inputStyle: { 'width': '300px' },
            },
            {
              label: "label_fms_account_apply_status", key: "status", type: 'select', enum: 'FmsCreditApplyStatus', attrs: { clearable: true },
            },
            {
              label: "label_fms_account_apply_apply_date",
              key: "applyTimeStart",
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
            {
              label: "-",
              key: "applyTimeEnd",
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
            {
              label: "label_fms_account_apply_audit_date",
              key: "auditTimeStart",
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
            {
              label: "-",
              key: "auditTimeEnd",
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
          ]
        },
        action: [

          {
            label: 'label_fms_recharge_add_record', attrs: { icon: "el-icon-plus" }, click: () => {

              this.$refs.rechargeDialog.showNew({
                title: this.$t("label_fms_recharge_add_record"),
                data: { isTransToOtherAccount: "N" },
                onlySetData: true,
              })
            }
          },

        ],

        actionExtra: [
          {
            label: 'label_export', click: this.exportExcel
          },
        ],
        table: {
          url: "/fms-api/customer/CustomerRechargeLogRpc/select.json",
          attrs: {
            'cell-style': ({ row, column, rowIndex, columnIndex }) => {
              if (column.property == 'status') {
                return { color: row.status == 'NORMAL' ? this.$globalCss.successColor : this.$globalCss.infoColor }
              }
            }
          },
          model: [
            { type: 'selection', clickToggle: true, keyGroup: 'label_table_operate' },
            { key: 'customerName', label: 'label_customer_name', 'width': 130, },
            { key: 'customerCode', label: 'label_customer_code', 'width': 130, },
            {
              key: 'accountType', label: 'label_fms_recharge_account',
              attrs: {
                formatter: (r, c, v, i) => {
                  return this.$enumShow(r.currencyType, 'CurrencyTypeEnum') + ' - ' + this.$enumShow(v, 'CustomerAccountTypeEnum')
                }
              }
            },
            {
              key: 'exchangeCurrencyType', label: 'label_exchange_transfer_account',
              attrs: {
                formatter: (r, c, v, i) => {
                  if (r.exchangeAccountId) {
                    return this.$enumShow(r.exchangeCurrencyType, 'CurrencyTypeEnum') + ' - ' + this.$enumShow(r.accountType, 'CustomerAccountTypeEnum')
                  }
                }
              }
            },
            {
              key: 'bankCardNo', label: 'label_fms_recharge_pay_card',
              attrs: {
                formatter: (r, c, v, i) => {

                  if (r.bankCardNo && r.bankName) {
                    return r.bankName + ' (' + (r.bankCardNo.length > 4 ? r.bankCardNo.substring(r.bankCardNo.length - 4) : r.bankCardNo) + ')'
                  }
                  return ''
                }
              }
            },
            { key: 'applyAmount', label: 'label_fms_recharge_recharge_amount', align: 'right' },
            {
              key: 'status', label: 'label_fms_account_apply_status',
              attrs: {
                formatter: (r, c, v, i) => {

                  return this.$enumShow(v, 'FmsCreditApplyStatus')
                }
              }
            },
            {
              key: 'remark', label: 'label_remark', width: 100,
              render: (h, { row, column }) => {
                const value = row[column.property]
                if (value) {
                  return (<text_extra_tooltip_operate
                    value={value} ellipsis
                    data_type={column.property} data_id={row.id}
                  />)
                }
                return this.$renderText(h, row[column.property])
              }
            },
            { key: 'submitUserName', label: 'label_fms_account_apply_apply_user', align: 'center' },
            { key: 'auditUserName', label: 'label_fms_account_apply_audit_user', align: 'center' },
            {
              key: 'gmtCreate', label: 'label_fms_account_apply_apply_date', attrs: {
                formatter: (r, c, v, i) => {
                  return this.$dateFormat(v)
                }
              }
            },
            {
              key: 'submitTime', label: 'label_fms_recharge_payment_date', attrs: {
                formatter: (r, c, v, i) => {
                  return this.$dateFormat(v)
                }
              }
            },
            {
              key: 'auditTime', label: 'label_fms_account_apply_audit_date', attrs: {
                formatter: (r, c, v, i) => {
                  return this.$dateFormat(v)
                }
              }
            },
            { key: 'refuseReason', label: 'label_fms_account_apply_refuse_reason', align: 'left' },
            {
              type: 'operate', width: 160,
              operate: [
                {
                  label: 'label_view_detail', click: (row) => {
                    this.$refs.detailDialog.showNew({
                      title: this.$t("label_fms_recharge_record"),
                      data: row,
                      onlySetData: true,
                    })
                  }
                },
                {
                  if: (row) => {
                    return row.status == 'INIT'
                  },
                  label: 'label_fms_account_apply_audit', auth: 'fms_recharge_list_audit', click: (row) => {

                    this.$refs.aduitDialog.showNew({
                      title: this.$t("label_fms_recharge_record_review"),
                      data: Object.assign(_.cloneDeep(row), { type: 'DONE' }),
                      onlySetData: true,
                    })
                    return
                    // let _this = this
                    // let tmpForm = JSON.parse(JSON.stringify(row))
                    // tmpForm['type'] = 'DONE'
                    // this.formValue = tmpForm

                    // // 如果  /aliyun_oss/download 不在文件路径中，则加上
                    // if (this.formValue.files && this.formValue.files.length > 0) {

                    //   let fileOssPaths = []
                    //   this.formValue.files.forEach(file => {
                    //     if (file) {
                    //       if (file.indexOf('/aliyun_oss/download/') == -1) {
                    //         file = '/aliyun_oss/download/' + file
                    //         fileOssPaths.push(file)
                    //       }
                    //     }
                    //   })



                    //   this.formValue.files = fileOssPaths
                    //   this.formValue.uploadPath = fileOssPaths[0]

                    // }
                    // this.dialogFormVisible = true
                  }
                }
              ],
            }
          ]
        }
      },
      rechargeDialog: {
        customClass: 'dialog_auto',
        submitUrl: '/fms-api/customer/CustomerRechargeLogRpc/saveUpdate.json',
        submitDataHandle: (data) => {
          if (data.isTransToOtherAccount == 'N') data.exchangeAccountId = null
          data.files = data.files ? data.files.map(it => it.filePath) : []
          return data
        },
        form: {
          itemClass: "form_item_default",
          inputClass: "form_input_default",
          formClass: "form_default_col2 flex_row_wrap",
          model: [
                  {
                      key: 'customerId', label: 'label_fms_account_cmp_as_customer', type: 'common_customer_choose',

                  },
                  {
                      key: 'accountId', label: 'label_fms_recharge_account',
                      render: (h, { data, item }) => {
                        const controlFun = (params) => {
                          if (params.customerIds) {
                            return true
                          } else {
                            return {
                              netStop: true,
                              focusInnerData: [],
                              warnning: this.$tt("tip_please_select_first_customer"),
                            }
                          }
                        }
                        return <ex_select_auto
                          value={data.accountId}
                          onInput={e => this.$set(data, "accountId", e)}
                          url="/fms-api/customer/CustomerAccountRpc/query.json"
                          option={item => ({
                            label: `${this.$enumShow(item.currencyType, 'CurrencyTypeEnum')} - ${this.$enumShow(item.accountType, 'CustomerAccountTypeEnum')}`,
                            value: item.id
                          })}
                          urlParams={{ customerIds: data.customerId, accountType: 'CASH', status: 'ENABLE' }}
                          urlControl={controlFun} dependentId={data.customerId}
                        />
                      },
                  },
                  {
                      key: 'isTransToOtherAccount', label: 'label_is_in_exchange_transfer', type: 'radio-group',
                      enum: "YesOrNoEnum",
                  },
                  {
                      if: (data) => data.isTransToOtherAccount == 'Y',
                      key: 'exchangeAccountId', label: 'label_exchange_transfer_account',
                      rules: (data) => {
                        return [
                          { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
                          {
                            validator: (r, v, cb) => {
                              if (data.accountId == v) {
                                cb(this.$t("tip_recharge_account_no_some_exchange_transfer_account"))
                              } else {
                                cb()
                              }
                            }
                          }]
                      },
                      render: (h, { data, item }) => {
                        const controlFun = (params) => {
                          if (params.customerIds) {
                            return true
                          } else {
                            return {
                              netStop: true,
                              focusInnerData: [],
                              warnning: this.$tt("tip_please_select_first_customer"),
                            }
                          }
                        }
                        return <ex_select_auto
                          value={data.exchangeAccountId}
                          onInput={e => this.$set(data, "exchangeAccountId", e)}
                          url="/fms-api/customer/CustomerAccountRpc/query.json"
                          option={item => ({
                            label: `${this.$enumShow(item.currencyType, 'CurrencyTypeEnum')} - ${this.$enumShow(item.accountType, 'CustomerAccountTypeEnum')}`,
                            value: item.id
                          })}
                          urlParams={{ customerIds: data.customerId, accountType: 'CASH', status: 'ENABLE' }}
                          urlControl={controlFun} dependentId={data.customerId}
                        />
                      },

                  },
                  {
                      key: 'bankCardId', label: 'label_fms_recharge_collection_card', type: 'select',
                      url: '/fms-api/agent/AgentBankcardRpc/selectEnable.json', storeData: true,
                      option: { label: 'bankName', value: 'id' },
                      keyExtra: { bankName: "bankName", bankCardNo: "bankCardNo" },
                  },
                  {
                      key: 'bankName', label: 'label_fms_recharge_collection_card_name',
                  },
                  {
                      key: 'bankCardNo', label: 'label_fms_recharge_collection_card_no',
                  },
                  {
                      key: 'payBankName', label: 'label_fms_recharge_payment_card_name',
                  },
                  {
                      key: 'payBankCardNo', label: 'label_fms_recharge_payment_card_no',
                  },
                  {
                      key: 'paySerialNo', label: 'label_fms_recharge_payment_order_no',
                  },
                  {
                      key: 'applyAmount', label: 'label_recharge_amount',
                  },
                  {
                      key: 'submitTime', label: 'label_fms_recharge_payment_date', type: "date-picker",
                      attrs: {
                        placeholder: this.$t('tip_please_select'),
                        type: "datetime"
                      }
                  },
                  {
                      key: 'remark', label: 'label_remark',
                      itemClass: "", inputClass: "",
                  },

            {
              key: 'isUpload',
              label: 'label_fms_recharge_upload_credentials',
              render: (h, { data }) => {
                return (<ex_super_upload value={data.files} type="image"
                  onInput={e => this.$set(data, 'files', e)}
                  onIsUploadChange={e => this.$set(data, 'isUpload', e)}

                  limit={1} headers={{ targetFolder: 'fms/recharge' }}
                />)
              },

            },


          ],
          rules: {
            isUpload: {
              validator: (r, v, cb) => {
                if (v) {
                  cb(this.$tt("label_uploading"))
                } else {
                  cb()
                }
              }
            },
            customerId: { required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },
            accountId: { required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },
            exchangeAccountId: { required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },
            bankCardId: { required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },
            bankName: { required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },
            bankCardNo: { required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },
            // payBankName: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            // payBankCardNo: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            // paySerialNo: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            applyAmount: { required: true, pattern: /^(?!0\d)[1-9]\d{0,9}(?:\.\d{1,2})?$/, message: this.$tt('tip_type_must_more_and_less', { i18n: { type: true }, type: "label_recharge_amount", min: "1", max: "10000000000" }), trigger: 'change' },
          },
        }
      },
      aduitDialog: {
        customClass: 'dialog_auto',
        submitUrl: '/fms-api/customer/CustomerRechargeLogRpc/audit.json',
        submitType: "post",
        submitDataHandle: (data) => {
          // data.files = data.files ? data.files.map(it => it.filePath) : []
          if (data.type == "DONE") data.refuseReason = null
          return data
        },
        form: {

          itemClass: "form_item_mini", inputClass: "form_input_small bold",
          model: [
            { header: 'label_fms_account_log_apply_info' },
            {
              grid: [
                [
                  {
                    span: 12, col: {
                      key: 'customerName', label: 'label_customer_name', formType: "text",
                    },
                  },
                  {
                    span: 12, col: {
                      key: 'customerCode', label: 'label_customer_code', formType: "text",
                    },
                  },
                ],
                [
                  {
                    span: 12, col: {
                      key: 'accountId', label: 'label_fms_account_apply_account_category', formType: "text",
                      formatter: (r, c, v) => `${this.$enumShow(r.currencyType, 'CurrencyTypeEnum')} - ${this.$enumShow(r.accountType, 'CustomerAccountTypeEnum')}`,
                    },
                  },
                ],
                [
                  {
                    span: 12, col: {
                      key: 'isTransToOtherAccount', label: '是否入账转兑', formType: "text",
                      render: (h, { data, item }) => {
                        const value = data[item.key]
                        return this.$renderText(h, this.$enumShow(value ? value : 'N', "YesOrNoEnum"))
                      },
                    },
                  },
                  {
                    span: 12, col: {
                      if: (data) => data.isTransToOtherAccount == 'Y', formType: "text",
                      key: 'exchangeAccountId', label: '转兑账户',
                      formatter: (r, c, v) => `${this.$enumShow(r.currencyType, 'CurrencyTypeEnum')} - ${this.$enumShow(r.accountType, 'CustomerAccountTypeEnum')}`,
                    },
                  },

                ],
                [

                  {
                    span: 12, col: {
                      key: 'bankName', label: 'label_fms_recharge_collection_card_name', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),

                    },
                  },
                  {
                    span: 12, col: {
                      key: 'bankCardNo', label: 'label_fms_recharge_collection_card_no', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),

                    },
                  },
                ],
                [
                  {
                    span: 12, col: {
                      key: 'payBankName', label: 'label_fms_recharge_payment_card_name', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),
                    },
                  },
                  {
                    span: 12, col: {
                      key: 'payBankCardNo', label: 'label_fms_recharge_payment_card_no', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),
                    },
                  },
                ],
                [
                  {
                    span: 12, col: {
                      key: 'paySerialNo', label: 'label_fms_recharge_payment_order_no', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),
                    },
                  },
                ],
                [
                  {
                    span: 12, col: {
                      key: 'applyAmount', label: 'label_fms_recharge_recharge_amount', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),

                    },
                  },
                  {
                    span: 12, col: {
                      key: 'submitTime', label: 'label_fms_recharge_payment_date', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, this.$dateFormat(data[item.key])),

                    },
                  },
                ],
                [
                  {
                    span: 24, col: {
                      key: 'remark', label: 'label_remark', formType: "text",
                      itemClass: "", inputClass: "",
                    },
                  },
                ],
              ],
            },
            {
              key: 'files',
              label: 'label_fms_recharge_upload_credentials',
              render: (h, { data }) => {
                if (_.isEmpty(data.files)) return this.$renderText(h, null)
                return (<div class="flex_row_wrap">
                  {
                    data.files.map(it => (
                      <ex_image_view src={it}
                        preview-src-list={data.files}
                      />
                    ))
                  }
                </div>)
              },
            },
            { header: 'label_fms_account_log_examine_result' },

            {
              grid: [
                [
                  {
                    span: 12, col: {
                      key: 'type',
                      label: 'label_fms_account_log_examine_result',
                      type: "radio-group",
                      enum: "FmsCreditApplyStatus",
                      listHandler: (list) => list.filter(it => it != "INIT")
                    },
                  },
                  {
                    span: 12, col: {
                      if: (data) => data.type == 'FAIL',
                      key: 'refuseReason', label: 'label_fms_account_log_examine_fail_reason',
                    },
                  },

                ],

              ],
            },

          ],
          rules: {
            type: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },

          },
        }
      },
      detailDialog: {
        customClass: 'dialog_auto',
        form: {
          itemClass: "form_item_mini", inputClass: "form_input_small bold",
          model: [
            { header: 'label_fms_account_log_apply_info' },
            {
              grid: [
                [
                  {
                    span: 12, col: {
                      key: 'customerName', label: 'label_customer_name', formType: "text",
                    },
                  },
                  {
                    span: 12, col: {
                      key: 'customerCode', label: 'label_customer_code', formType: "text",
                    },
                  },
                ],
                [
                  {
                    span: 12, col: {
                      key: 'accountId', label: 'label_fms_account_apply_account_category', formType: "text",
                      formatter: (r, c, v) => `${this.$enumShow(r.currencyType, 'CurrencyTypeEnum')} - ${this.$enumShow(r.accountType, 'CustomerAccountTypeEnum')}`,
                    },
                  },
                ],
                [
                  {
                    span: 12, col: {
                      key: 'isTransToOtherAccount', label: '是否入账转兑', formType: "text",
                      render: (h, { data, item }) => {
                        const value = data[item.key]
                        return this.$renderText(h, this.$enumShow(value ? value : 'N', "YesOrNoEnum"))
                      },
                    },
                  },
                  {
                    span: 12, col: {
                      if: (data) => data.isTransToOtherAccount == 'Y', formType: "text",
                      key: 'exchangeAccountId', label: '转兑账户',
                      formatter: (r, c, v) => `${this.$enumShow(r.currencyType, 'CurrencyTypeEnum')} - ${this.$enumShow(r.accountType, 'CustomerAccountTypeEnum')}`,
                    },
                  },

                ],
                [

                  {
                    span: 12, col: {
                      key: 'bankName', label: 'label_fms_recharge_collection_card_name', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),

                    },
                  },
                  {
                    span: 12, col: {
                      key: 'bankCardNo', label: 'label_fms_recharge_collection_card_no', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),

                    },
                  },
                ],
                [
                  {
                    span: 12, col: {
                      key: 'payBankName', label: 'label_fms_recharge_payment_card_name', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),
                    },
                  },
                  {
                    span: 12, col: {
                      key: 'payBankCardNo', label: 'label_fms_recharge_payment_card_no', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),
                    },
                  },
                ],
                [
                  {
                    span: 12, col: {
                      key: 'paySerialNo', label: 'label_fms_recharge_payment_order_no', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),
                    },
                  },
                ],
                [
                  {
                    span: 12, col: {
                      key: 'applyAmount', label: 'label_fms_recharge_recharge_amount', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, data[item.key]),

                    },
                  },
                  {
                    span: 12, col: {
                      key: 'submitTime', label: 'label_fms_recharge_payment_date', formType: "text",
                      render: (h, { data, item }) => this.$renderText(h, this.$dateFormat(data[item.key])),

                    },
                  },
                ],
                [
                  {
                    span: 24, col: {
                      key: 'remark', label: 'label_remark', formType: "text",
                      itemClass: "", inputClass: "",
                    },
                  },
                ],
              ],
            },
            {
              key: 'files',
              label: 'label_fms_recharge_upload_credentials',
              render: (h, { data }) => {
                if (_.isEmpty(data.files)) return this.$renderText(h, null)
                return (<div class="flex_row_wrap">
                  {
                    data.files.map(it => (
                      <ex_image_view src={it}
                        preview-src-list={data.files}
                      />
                    ))
                  }
                </div>)
              },
            },
            { header: 'label_fms_account_log_examine_result' },

            {
              grid: [
                [
                  {
                    span: 12, col: {
                      key: 'status',
                      label: 'label_fms_account_log_examine_result',
                      formType: "text",
                      render: (h, { data, item }) => {
                        return this.$renderText(h, this.$enumShow(data[item.key], 'FmsCreditApplyStatus'))
                      },
                    },
                  },
                  {
                    span: 12, col: {
                      if: (data) => data.status == 'FAIL',
                      key: 'refuseReason', label: 'label_fms_account_log_examine_fail_reason',
                      formType: "text",
                      render: (h, { data, item }) => {
                        let value = data[item.key]
                        return this.$renderText(h, value)
                      },
                    },
                  },


                ],

              ],
            },
          ],
        }
      },
    };
  },




  created() {


  },

  methods: {
    exportExcel() {
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: this.$refs.SuperTablePage.getSearchFormData(),
        model: this.option.search.model,
        selection: this.selection,
        callback: (selection, data) => {
          let params = {}
          if (!_.isEmpty(selection)) {
            params = {
              idList: selection.map(it => it.id)
            }
          } else {
            params = data
          }
          this.$functionCommon({
            url: '/fms-api/customer/CustomerRechargeLogRpc/export.json',
            data: params
          })
        }
      })
    },

  }
};

</script>
<style></style>
